package com.csw.android.ffmpegtest.ui.main

import android.graphics.Color
import android.os.Bundle
import android.view.View
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.csw.android.dev_utils.utils.SpaceLineDecoration
import com.csw.android.ffmpegtest.R
import com.csw.android.ffmpegtest.databinding.ActivityMainBinding
import com.csw.android.ffmpegtest.ui.base.DataBindingActivity

/**
 * 本项目用于根据这个博文的学习路线来学习ffmpeg
 * https://blog.51cto.com/ticktick/1956269
 */
class MainActivity : DataBindingActivity<ActivityMainBinding>() {

    private var sectionAdapter: SectionAdapter? = null

    override fun getContentViewID(): Int {
        return R.layout.activity_main
    }

    override fun initView(rootView: View, savedInstanceState: Bundle?) {
        super.initView(rootView, savedInstanceState)
        dataBinding?.mainViewModel = ViewModelProvider(this).get(MainViewModel::class.java)
        dataBinding?.recyclerView?.run {
            layoutManager = LinearLayoutManager(this@MainActivity)
            addItemDecoration(SpaceLineDecoration.getInstanceByDp(0, 0, 0, 1, Color.BLACK))
        }
    }

    override fun initAdapter() {
        super.initAdapter()
        sectionAdapter = SectionAdapter().apply {
            dataBinding?.recyclerView?.adapter = this
        }
    }

    override fun initListener() {
        super.initListener()
        dataBinding?.mainViewModel?.list?.observe(this@MainActivity) {
            sectionAdapter?.setNewInstance(it)
        }
    }

    override fun initData() {
        super.initData()

    }
}